package User;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Test {
    public static void main(String[] args) {

        System.out.println(getcode());

    }

    private static String getcode() {
        //1.创建集合
        ArrayList<Character> list=new ArrayList<>();
        //将大小写字母放在集合list当中
        for (int i = 0; i < 26; i++) {
            list.add((char) ('a' + i));
            list.add((char) ('A' + i));
        }
       //获取4个随机验证码
        StringBuffer sb=new StringBuffer();
        Random r=new Random();
        for (int i = 0; i < 4; i++) {
            int index = r.nextInt(list.size());
            sb.append(list.get(index));

        }
        //System.out.println(sb);
        //获取一个数字
        int number = r.nextInt(10);
        sb.append(number);
        //打乱数字排序的地方
       char []arr= sb.toString().toCharArray();
        for (int i = 0; i < arr.length; i++) {
            int index = r.nextInt(arr.length);
            char tmp=arr[index];
            arr[index]=arr[i];
            arr[i]=tmp;
        }
        return new String(arr);
    }

}
